import 'package:flutter/material.dart';
import 'package:battery_optimizations/battery_optimization.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Disable Battery Optimizations Plugin example app')),
        body: Center(
          child: Column(
            children: <Widget>[
              MaterialButton(
                child: Text("Is Auto Start Enabled"),
                onPressed: () async {
                  bool isAutoStartEnabled = await BatteryOptimization.isAutoStartEnabled;
                  print("Auto start is ${isAutoStartEnabled ? "Enabled" : "Disabled"}");
                },
              ),
              MaterialButton(
                child: Text("Is Battery optimization disabled"),
                onPressed: () async {
                  bool isBatteryOptimizationDisabled = await BatteryOptimization.isBatteryOptimizationDisabled;
                  print("Battery optimization is ${!isBatteryOptimizationDisabled ? "Enabled" : "Disabled"}");
                },
              ),
              MaterialButton(
                child: Text("Is Manufacturer Battery optimization disabled"),
                onPressed: () async {
                  bool isManBatteryOptimizationDisabled = await BatteryOptimization.isManufacturerBatteryOptimizationDisabled;
                  print("Manufacturer Battery optimization is ${!isManBatteryOptimizationDisabled ? "Enabled" : "Disabled"}");
                },
              ),
              MaterialButton(
                child: Text("Are All Battery optimizations disabled"),
                onPressed: () async {
                  bool isAllBatteryOptimizationDisabled = await BatteryOptimization.isAllBatteryOptimizationDisabled;
                  print("All Battery optimizations are disabled ${isAllBatteryOptimizationDisabled ? "True" : "False"}");
                },
              ),
              MaterialButton(
                child: Text("Enable Auto Start"),
                onPressed: () {
                  BatteryOptimization.showEnableAutoStartSettings("Enable Auto Start", "Follow the steps and enable the auto start of this app");
                },
              ),
              MaterialButton(
                child: Text("Disable Battery Optimizations"),
                onPressed: () {
                  BatteryOptimization.showDisableBatteryOptimizationSettings();
                },
              ),
              MaterialButton(
                child: Text("isInteractive"),
                onPressed: () async {
                  await Future.delayed(Duration(seconds: 3));
                  print("isInteractive = ${await BatteryOptimization.isInteractive}");
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
